package com.zmsk.zmio.handler;

import android.content.Context;
import android.util.Log;

import com.zmsk.zmio.inter.IIOHandler;
import com.zmsk.zmio.ysface88.YSGpioUtils;

public class YSV88Handler implements IIOHandler {

    private static final String TAG = "YSLM8Handler";

    public YSV88Handler(Context context) {
        initIOControl(context);
    }

    @Override
    public void initIOControl(Context context) {
        Log.d(TAG, "initIOControl");
        try {
            YSGpioUtils.upgradeRootPermissionForExport();
            //IO2
            if (YSGpioUtils.exportGpio(138)) {
                YSGpioUtils.upgradeRootPermissionForGpio(138);
            }
            YSGpioUtils.setGpioDirection(138, 0);
            //IO1
            if (YSGpioUtils.exportGpio(139)) {
                YSGpioUtils.upgradeRootPermissionForGpio(139);
            }
            YSGpioUtils.setGpioDirection(139, 0);
            //IO3
            if (YSGpioUtils.exportGpio(62)) {
                YSGpioUtils.upgradeRootPermissionForGpio(62);
            }
            YSGpioUtils.setGpioDirection(62, 0);
            //IO4
            if (YSGpioUtils.exportGpio(65)) {
                YSGpioUtils.upgradeRootPermissionForGpio(65);
            }
            YSGpioUtils.setGpioDirection(65, 0);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void stopIOControl(Context context) {

    }

    @Override
    public void noticeGateOpen(Context context, String idNumber) {
        YSGpioUtils.writeGpioValue(65, "1");

    }

    @Override
    public void noticeGateClose(Context context) {
        YSGpioUtils.writeGpioValue(65, "0");
    }

    @Override
    public void noticeWhiteLedOn(Context context) {
        YSGpioUtils.writeGpioValue(138, "1");
    }

    @Override
    public void noticeWhiteLedOff(Context context) {
        YSGpioUtils.writeGpioValue(138, "0");
    }

    @Override
    public void noticeInfraredLedOn(Context context) {
        YSGpioUtils.writeGpioValue(139, "1");
    }

    @Override
    public void noticeInfraredLedOff(Context context) {
        YSGpioUtils.writeGpioValue(139, "0");
    }

    @Override
    public void noticeRedLedOn(Context context) {
        YSGpioUtils.writeGpioValue(139, "1");
    }

    @Override
    public void noticeRedLedOff(Context context) {
        YSGpioUtils.writeGpioValue(139, "0");
    }

    @Override
    public void noticeGreenLedOn(Context context) {
        YSGpioUtils.writeGpioValue(62, "1");    }

    @Override
    public void noticeGreenLedOff(Context context) {
        YSGpioUtils.writeGpioValue(62, "0");
    }

    @Override
    public void handleSlientInstall(String path) {

    }
}
